#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e6+5;
int n,a[N],b[N];
inline void solve()
{
	cin>>n;
	for(int i = 1;i<=n;i++)
		cin>>a[i];
	for(int i = 1;i<=n;i++)
		cin>>b[i];
	int las = 0,fl = 0,ans = 0;
	for(int i = 1;i<=n;i++) if(a[i]==0) return cout<<"-1",void();
	for(int i = 1;i<=n;i++)
	{
		if((a[i]<=b[i])==fl) ans+=max(abs(a[i]-b[i])-las,0ll);
		else ans+=abs(a[i]-b[i]),fl^=1;
		las = abs(a[i]-b[i]);
	}
	cout<<ans<<'\n';
}
signed main()
{
	freopen("game.in","r",stdin);
	freopen("game.out","w",stdout);
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int T;cin>>T;
	while(T--) solve();
	return 0;
}

